package com.kq.tallybookl.util;

import com.kq.tallybookl.R;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Kq on 2016/5/2.
 */
public class GetTime {
     /**
     * 生成指定的时间格式
     *
     * @param timestamp 传入时间长度，以毫秒为单位
     * @return 返回特定格式的字符串
     */
    public static String getBottomTimeString(long timestamp) {
        String timeText = "";

        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        Date date = new Date(timestamp);
        String hour = format.format(date);

        String week = "";

        // 获取日历类实例
        Calendar c = Calendar.getInstance();
        // 设置时间
        c.setTime(new Date(timestamp));

        // 获取该时间的星期格式
        switch (c.get(Calendar.DAY_OF_WEEK)) {
            case 1:
                week = "星期天";
                break;
            case 2:
                week = "星期一";
                break;
            case 3:
                week = "星期二";
                break;
            case 4:
                week = "星期三";
                break;
            case 5:
                week = "星期四";
                break;
            case 6:
                week = "星期五";
                break;
            case 7:
                week = "星期六";
                break;
            default:
                break;
        }

        // 按照特定格式排列
        timeText = week+" "+hour;


        return timeText;
    }

    public static String getYearTimeString(long timestamp){
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = new Date(timestamp);
        return format.format(date);
    }

}
